//-----------------------------------------------------------------------------
// File: RepeatedLabel.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;

namespace ObjectiveDraw.Platform.Controls
{
	/// <summary>
	/// Summary description for RepeatedLabel.
	/// </summary>
	public class RepeatedLabel : Cerebrum.Direct3D.Forms.Control, Cerebrum.Direct3D.Forms.IShdRepeatedControl
	{
		public Cerebrum.Direct3D.Forms.Label Label;

		public string [] TextLines;

		public RepeatedLabel()
		{
			Label = new Cerebrum.Direct3D.Forms.Label();
			Label.Location = new System.Drawing.PointF(0, 0);
			Label.Size = this.Size;
			Label.Visible = true;
			this.Controls.Add(Label);
		}
		#region IShdRepeatedControl Members

		protected int m_Index;

		public int Index
		{
			get
			{
				return m_Index;
			}
			set
			{
				m_Index = value;
				if(m_Index < 0)
				{
					this.Label.Text = string.Empty;
				}
				else
				{
					if(m_Index < TextLines.Length)
					{
						this.Label.Text = TextLines[m_Index];
					}
					else
					{
						this.Label.Text = m_Index.ToString();
					}
				}
				RefreshLayout();
			}
		}

		private bool m_Scrolling;
		public bool Scrolling
		{
			get
			{
				return m_Scrolling;
			}
			set
			{
				m_Scrolling = value;
			}
		}

		#endregion

		private void RefreshLayout()
		{
			if(this.Label.Text.Length > 0)
			{
				System.Drawing.SizeF size = this.Label.Font.GetTextExtent(this.Label.Text);
				this.Label.Location = new System.Drawing.PointF((this.Size.Width - size.Width) / 2, 0);
				this.Label.Size = size;
			}
			else
			{
				this.Label.Location = new System.Drawing.PointF(0, 0);
				this.Label.Size = this.Size;
			}
		}
		protected override void OnResize(EventArgs e)
		{
			base.OnResize (e);
			RefreshLayout();
		}

	}
}
